package cn.aib.staservice.controller;


import cn.aib.commonutils.R;
import cn.aib.staservice.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-01-26
 */
@RestController
@RequestMapping("/staservice/statistics")
//@CrossOrigin
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsService;

    @PostMapping("createStatistics/{date}")
    public R createStatistics(@PathVariable String date){

        Integer i = statisticsService.saveSta(date);

        if(i<=0){
            return R.error();
        }

        return R.ok();
    }

    @GetMapping("showChart/{type}/{begin}/{end}")
    public R showChart(@PathVariable String type,@PathVariable String begin,@PathVariable String end){
        System.out.println(type+":"+begin+":"+end);
        Map<String, Object> map = statisticsService.showStaData(type,begin,end);
        System.out.println(map);
        return R.ok().data(map);
    }

}

